define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/vipcombo/index' + location.search,
                    add_url: 'user/vipcombo/add',
                    edit_url: 'user/vipcombo/edit',
                    //del_url: 'user/vipcombo/del',
                    multi_url: 'user/vipcombo/multi',
                    import_url: 'user/vipcombo/import',
                    table: 'user_vip_combo',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                sortOrder: 'asc',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'id', title: __('序号'), formatter: function (value, row, index) {
                                return index + 1;
                            },
                            align: 'left',
                            searchable: false
                        },
                        {field: 'app_id', title: __('租户编号'), visible: false, align: 'left'},
                        {field: 'app.app_name', title: __('租户'), searchable: false, align: 'left'},
                        {field: 'name', title: __('名称'),align: 'left', operate: 'LIKE'},
                        {field: 'sale_price', title: __('售价'),align: 'left', operate:'BETWEEN'},
                        {field: 'original_price', title: __('原价'),align: 'left', operate:'BETWEEN'},
                        {field: 'expire', title: __('时长'),align: 'left'},
                        {
                            field: 'expire_type',
                            title: __('单位'),
                            formatter: Table.api.formatter.flag,
                            searchList: {'1': __('秒'), '2': __('分'), '3': __('时'), '4': __('天'), '5': __('月'), '6': __('年')},
                            align: 'left'
                        },
                        {field: 'score', title: __('赠送积分'),align: 'left'},
                        {
                            field: 'status',
                            title: __('状态'),
                            formatter: Table.api.formatter.normal,
                            searchList: {'1': __('启用'), '2': __('停用')},
                            align: 'left'
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
